<?php session_start(); ?>
<?php 
	include_once('misc/class_config.php'); 
	include_once('model/country.php');
?>

<?php 
	include_once('access_control/page_access.php');	
	
	setPreviousPage();
	declinePageIfNotLoggedIn();
	
	$currentUser = new user();
	$currentUser->isLoggedIn();
	$currentUser->isTimedOut();
	$accountValidationError = new validation();
	$accountMessage="";
?>

<?php 
	if(isset($_REQUEST['action']))
	{
		if($_REQUEST['action']=="changepassword")
		{
				include_once "controller/changepasswordformcontroller.php";
		}
		else if($_REQUEST['action']=="editpaymentaccount")
		{
			include_once "controller/accountpaymentformcontroller.php"; 
		}
		else
		{
			include_once "controller/accountcontroller.php"; 
		}
	}
	else if(isset($_POST['btnChangePassword']))
	{
		include_once "controller/changepasswordformcontroller.php";
	}
	else if(isset($_POST['btnSavePayment']))
	{
		include_once "controller/accountpaymentformcontroller.php";
	}
	else
	{
		include_once "controller/accountcontroller.php"; 
	}
?>

<?php $pageTitle = $currentUser->firstName."'s Account"." | Everything"; ?>
<?php include('layout/page_start.php'); ?>
<?php include('layout/page_header.php'); ?>
<?php include('layout/menu_bar.php'); ?>

<div id="main_content_div">
	
	<?php
		echo '<div class="page_action_msg_div"><p>'.$accountMessage.'</p></div>';
		if($currentUser->loggedIn)
		{
			if($currentUser->timedOut)
			{
				include_once "layout/timeout.php";
				$currentUser->timeoutUser();
			}
			else
			{
				echo '<br/><a href="account.php" title="Basic Information">Basic Information<a/> | <a href="account.php?action=changepassword" title="Change your password">Change Password<a/>'; 
				if($currentUser->type=="user")
				{
					echo '| <a href="account.php?action=editpaymentaccount" title="Edit your payment account">Edit Payment Account<a/>';
				}
				echo "<br/>";
				if(isset($_REQUEST['action']))
				{
					if($_REQUEST['action']=="changepassword")
					{
							include_once "layout/change_password_form.php";
					}
					else if($_REQUEST['action']=="editpaymentaccount")
					{
						include_once "layout/change_payment_form.php"; 
					}
					else
					{
						include_once "layout/accountform.php"; 
					}
				}
				else if(isset($_POST['btnChangePassword']))
				{

					include_once "layout/change_password_form.php";
				}
				else if(isset($_POST['btnSavePayment']))
				{
					include_once "layout/change_payment_form.php";
				}
				else
				{
					include_once "layout/accountform.php"; 
				}			
			}
		}	
	?>
</div>
<?php include('layout/page_footer.php'); ?>
<?php include('layout/page_end.php'); ?>
<?php setCurrentPage();?>